package com.yunhe.abnormal.controller.base;

import com.yunhe.abnormal.domain.base.AlarmLevel;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.base.AlarmLevelDTO;
import com.yunhe.abnormal.service.base.AlarmLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "alarmLevel", description = "告警级别维护", tags = "Base_AlarmLevel")
@RestController
@RequestMapping("/alarmLevels")
public class AlarmLevelController {

    @Autowired
    private AlarmLevelService alarmLevelService;

    @ApiOperation("新增告警级别")
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<ResultObject> create(@RequestBody AlarmLevel alarmLevel) {
        AlarmLevelDTO result = alarmLevelService.create(alarmLevel);
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("查询告警级别")
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<ResultObject> search() {
        Iterable<AlarmLevelDTO> result = alarmLevelService.findAll();
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("根据异常代码获取告警级别代码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "alarmId", value = "设备告警状态ID", required = true, dataType = "long", paramType = "path"),
    })
    @RequestMapping(value = "/byAlarmId/{alarmId}", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> getAlarmLevelCodeByAlarmId(@PathVariable("alarmId") Long alarmId) {
        AlarmLevelDTO result = alarmLevelService.findAlarmLevelByAlarmId(alarmId);
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("根据异常代码Id获取告警级别代码")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> getAlarmLevelCodeById(@PathVariable("id") Long id) {
        AlarmLevelDTO result = alarmLevelService.findById(id);
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("根据ID删除告警等级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "告警状态ID", required = true, dataType = "long", paramType = "path")
    })
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public ResponseEntity<ResultObject> delete(@PathVariable("id") Long id) {
        alarmLevelService.delete(id);
        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
    }

    @ApiOperation("根据设备/电站ID获取对应的告警点号的告警等级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "objectId", value = "电站ID", dataType = "long", paramType = "query")
    })
    @RequestMapping(value = "/name/byObjectId", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> getAlarmLevelNameByObjectId(@RequestParam("objectId") Long objectId) {
        List<String> result = alarmLevelService.getAlarmLevelNameByObjectId(objectId);
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }
}
